import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProReceiveMoneyQuery, ProReceiveMoneyForm, ProReceiveMoneyVO, ProReceiveLogVO, ProPlanAuditVO } from './types';
import { ProReceiveRegisterVO, ProReceiveRegisterForm, ProReceiveRegisterQuery } from '@/api/project/receive/types';

/**
 * 查询项目回款信息列表
 * @param query 查询参数
 * @returns 项目回款信息列表
 */
export function listProReceiveMoney(query: ProReceiveMoneyQuery): AxiosPromise<ProReceiveMoneyVO[]> {
  return request({
    url: '/pro/receive/list',
    method: 'get',
    params: query
  });
}

/**
 * 获取项目回款信息详细
 * @param id 回款信息ID
 * @returns 项目回款信息详细
 */
export function getProReceiveMoney(id: string | number): AxiosPromise<ProReceiveMoneyVO> {
  return request({
    url: '/pro/receive/' + id,
    method: 'get'
  });
}

/**
 * 新增项目回款信息
 * @param data 回款信息数据
 * @returns 新增结果
 */
export function addProReceiveMoney(data: ProReceiveMoneyForm) {
  return request({
    url: '/pro/receive',
    method: 'post',
    data: data
  });
}

/**
 * 修改项目回款信息
 * @param data 回款信息数据
 * @returns 修改结果
 */
export function updateProReceiveMoney(data: ProReceiveMoneyForm) {
  return request({
    url: '/pro/receive',
    method: 'put',
    data: data
  });
}

/**
 * 删除项目回款信息
 * @param id 回款信息ID
 * @returns 删除结果
 */
export function delProReceiveMoney(id: string | number | Array<string | number>) {
  return request({
    url: '/pro/receive/' + id,
    method: 'delete'
  });
}

/**
 * 单个保存项目回款节点
 * @param data 回款节点数据
 * @returns 保存结果
 */
export function saveReceiveMoneyNode(data: ProReceiveMoneyForm) {
  return request({
    url: '/pro/receive',
    method: 'post',
    data: data
  });
}

/**
 * 根据项目ID查询回款节点列表
 * @param proId 项目ID
 * @returns 回款节点列表
 */
export function getReceiveMoneyNodesByProId(proId: string | number): AxiosPromise<ProReceiveMoneyVO[]> {
  return request({
    url: '/pro/receive/list',
    method: 'get',
    params: { proId }
  });
}

/**
 * 导出项目回款信息
 * @param query 查询参数
 * @returns 导出结果
 */
export function exportProReceiveMoney(query: ProReceiveMoneyQuery) {
  return request({
    url: '/pro/receive/export',
    method: 'post',
    data: query
  });
}

/**
 * 查询节点日志列表
 * @param receiveId 回款节点ID
 * @returns 日志列表
 */
export function getReceiveMoneyLog(receiveId: string | number): AxiosPromise<ProReceiveLogVO[]> {
  return request({
    url: '/pro/receive/log/' + receiveId,
    method: 'get'
  });
}

/**
 * 删除项目回款节点信息
 * @param id 节点ID
 * @returns 删除结果
 */
export function removeReceiveMoneyNode(id: string | number) {
  return request({
    url: '/pro/receive/' + id,
    method: 'delete'
  });
}

/**
 * 重置回款以下的所有审核信息
 * @param id 项目ID
 * @returns 重置结果
 */
export function revertReceiveMoneyAuditFlow(id: string | number) {
  return request({
    url: '/pro/receive/revert/' + id,
    method: 'get'
  });
}

/**
 * 根据合同ID查询到达回款节点的回款记录信息
 * @param conId 合同ID
 * @returns 到达回款节点的回款记录列表
 */
export function getArrivedReceiveNodesByContractId(conId: string | number): AxiosPromise<ProReceiveMoneyVO[]> {
  return request({
    url: '/pro/receive/arrivedNodes/' + conId,
    method: 'get'
  });
}

//  回款登记相关API

/**
 * 查询回款登记列表
 * @param query
 * @returns {*}
 */

export const listProReceiveRegister = (query?: ProReceiveRegisterQuery): AxiosPromise<ProReceiveRegisterVO[]> => {
  return request({
    url: '/pro/receive/registerPage',
    method: 'get',
    params: query
  });
};

/**
 * 查询回款登记详细
 * @param id
 */
export const getProReceiveRegister = (id: string | number): AxiosPromise<ProReceiveRegisterVO> => {
  return request({
    url: '/pro/receive/registerInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增回款登记
 * @param data
 */
export const addProReceiveRegister = (data: ProReceiveRegisterForm) => {
  return request({
    url: '/pro/receive/saveRegister',
    method: 'post',
    data: data
  });
};

/**
 * 修改回款登记
 * @param data
 */
export const updateProReceiveRegister = (data: ProReceiveRegisterForm) => {
  return request({
    url: '/pro/receive/updateRegister',
    method: 'put',
    data: data
  });
};

/**
 * 删除回款登记
 * @param id
 */
export const delProReceiveRegister = (id: string | number | Array<string | number>) => {
  return request({
    url: '/pro/receive/delRegister/' + id,
    method: 'delete'
  });
};

/**
 * 获取项目计划审核列表（以flow为最小单位）
 */
export function getPlanAuditList(proId: string | number): AxiosPromise<ProPlanAuditVO[]> {
  return request({
    url: '/pro/receive/auditList',
    method: 'get',
    params: { proId }
  });
}
